{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Highcharts Demos\n",
    "================\n",
    "3D scatter chart: http://www.highcharts.com/demo/3d-scatter-draggable\n",
    "---------------------------------------------------------------------"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false,
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<iframe style=\"border:0;outline:none;overflow:hidden\" src=\"data:text/html,&lt;!DOCTYPE html&gt;\n",
       "&lt;html lang=&quot;en&quot;&gt;\n",
       "    &lt;head&gt;\n",
       "        &lt;meta charset=&quot;utf-8&quot; /&gt;\n",
       "        &lt;link href=&quot;https://www.highcharts.com/highslide/highslide.css&quot; rel=&quot;stylesheet&quot; /&gt;\n",
       "        &lt;script type=&quot;text/javascript&quot; src=&quot;https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js&quot;&gt;&lt;/script&gt;\n",
       "        &lt;script type=&quot;text/javascript&quot; src=&quot;https://code.highcharts.com/highcharts.js&quot;&gt;&lt;/script&gt;\n",
       "        &lt;script type=&quot;text/javascript&quot; src=&quot;https://code.highcharts.com/highcharts-more.js&quot;&gt;&lt;/script&gt;\n",
       "        &lt;script type=&quot;text/javascript&quot; src=&quot;https://code.highcharts.com/modules/exporting.js&quot;&gt;&lt;/script&gt;\n",
       "        &lt;script type=&quot;text/javascript&quot; src=&quot;http://code.highcharts.com/highcharts-3d.js&quot;&gt;&lt;/script&gt;\n",
       "    &lt;/head&gt;\n",
       "    &lt;body style=&quot;margin:0;padding:0&quot;&gt;\n",
       "                &lt;div id=&quot;container&quot; style=&quot;width:550px;height:400px;&quot;&gt;Loading....&lt;/div&gt;\n",
       "\n",
       "\n",
       "    &lt;script&gt;\n",
       "        $(function(){\n",
       "\n",
       "\n",
       " \n",
       "\n",
       "\n",
       "\n",
       "\n",
       "            Highcharts.setOptions({&quot;lang&quot;: {}, &quot;global&quot;: {}});\n",
       "            var option = {&quot;loading&quot;: {}, &quot;subtitle&quot;: {&quot;text&quot;: &quot;Click and drag the plot area to rotate in space&quot;}, &quot;xAxis&quot;: {&quot;max&quot;: 10, &quot;gridLineWidth&quot;: 1, &quot;min&quot;: 0}, &quot;title&quot;: {&quot;text&quot;: &quot;Draggable box&quot;}, &quot;series&quot;: {}, &quot;labels&quot;: {}, &quot;yAxis&quot;: {&quot;max&quot;: 10, &quot;min&quot;: 0}, &quot;chart&quot;: {&quot;width&quot;: 550, &quot;type&quot;: &quot;scatter&quot;, &quot;options3d&quot;: {&quot;beta&quot;: 30, &quot;viewDistance&quot;: 5, &quot;alpha&quot;: 10, &quot;frame&quot;: {&quot;side&quot;: {&quot;color&quot;: &quot;rgba(0,0,0,0.06)&quot;, &quot;size&quot;: 1}, &quot;back&quot;: {&quot;color&quot;: &quot;rgba(0,0,0,0.04)&quot;, &quot;size&quot;: 1}, &quot;bottom&quot;: {&quot;color&quot;: &quot;rgba(0,0,0,0.02)&quot;, &quot;size&quot;: 1}}, &quot;enabled&quot;: true, &quot;depth&quot;: 250}, &quot;renderTo&quot;: &quot;container&quot;, &quot;margin&quot;: 100, &quot;height&quot;: 400}, &quot;tooltip&quot;: {}, &quot;plotOptions&quot;: {&quot;scatter&quot;: {}}, &quot;credits&quot;: {&quot;enabled&quot;: false}, &quot;colors&quot;: Highcharts.getOptions().colors = $.map(Highcharts.getOptions().colors, function (color) {\n",
       "        return {\n",
       "            radialGradient: {\n",
       "                cx: 0.4,\n",
       "                cy: 0.3,\n",
       "                r: 0.5\n",
       "            },\n",
       "            stops: [\n",
       "                [0, color],\n",
       "                [1, Highcharts.Color(color).brighten(-0.2).get(&#x27;rgb&#x27;)]\n",
       "            ]\n",
       "        };\n",
       "    }), &quot;zAxis&quot;: {&quot;max&quot;: 10, &quot;showFirstLabel&quot;: false, &quot;min&quot;: 0}, &quot;pane&quot;: {}, &quot;exporting&quot;: {}, &quot;drilldown&quot;: {}, &quot;navigation&quot;: {}, &quot;legend&quot;: {&quot;enabled&quot;: false}};\n",
       "\n",
       "\n",
       "            var data = [{&quot;colorByPoint&quot;: true, &quot;data&quot;: [[1, 6, 5], [8, 7, 9], [1, 3, 4], [4, 6, 8], [5, 7, 7], [6, 9, 6], [7, 0, 5], [2, 3, 3], [3, 9, 8], [3, 6, 5], [4, 9, 4], [2, 3, 3], [6, 9, 9], [0, 7, 0], [7, 7, 9], [7, 2, 9], [0, 6, 2], [4, 6, 7], [3, 7, 7], [0, 1, 7], [2, 8, 6], [2, 3, 7], [6, 4, 8], [3, 5, 9], [7, 9, 5], [3, 1, 7], [4, 4, 2], [3, 6, 2], [3, 1, 6], [6, 8, 5], [6, 6, 7], [4, 1, 1], [7, 2, 7], [7, 7, 0], [8, 8, 9], [9, 4, 1], [8, 3, 4], [9, 8, 9], [3, 5, 3], [0, 2, 4], [6, 0, 2], [2, 1, 3], [5, 8, 9], [2, 1, 1], [9, 7, 6], [3, 0, 2], [9, 9, 0], [3, 4, 8], [2, 6, 1], [8, 9, 2], [7, 6, 5], [6, 3, 1], [9, 3, 1], [8, 9, 3], [9, 1, 0], [3, 8, 7], [8, 0, 0], [4, 9, 7], [8, 6, 2], [4, 3, 0], [2, 3, 5], [9, 1, 4], [1, 1, 4], [6, 0, 2], [6, 1, 6], [3, 8, 8], [8, 8, 7], [5, 5, 0], [3, 9, 6], [5, 4, 3], [6, 8, 3], [0, 1, 5], [6, 7, 3], [8, 3, 2], [3, 8, 3], [2, 1, 6], [4, 6, 7], [8, 9, 9], [5, 4, 2], [6, 1, 3], [6, 9, 5], [4, 8, 2], [9, 7, 4], [5, 4, 2], [9, 6, 1], [2, 7, 3], [4, 5, 4], [6, 8, 1], [3, 4, 0], [2, 2, 6], [5, 1, 2], [9, 9, 7], [6, 9, 9], [8, 4, 3], [4, 1, 7], [6, 2, 5], [0, 4, 9], [3, 5, 9], [6, 9, 1], [1, 9, 2]], &quot;type&quot;: &quot;scatter&quot;, &quot;name&quot;: &quot;Reading&quot;}];\n",
       "            option.series = data;\n",
       "\n",
       " \n",
       "\n",
       "            var chart = new Highcharts.Chart(option);\n",
       "\n",
       "\n",
       "            $(chart.container).bind(&#x27;mousedown.hc touchstart.hc&#x27;, function (e) {\n",
       "                e = chart.pointer.normalize(e);\n",
       "\n",
       "                var posX = e.pageX,\n",
       "                    posY = e.pageY,\n",
       "                    alpha = chart.options.chart.options3d.alpha,\n",
       "                    beta = chart.options.chart.options3d.beta,\n",
       "                    newAlpha,\n",
       "                    newBeta,\n",
       "                    sensitivity = 5;\n",
       "\n",
       "                $(document).bind({\n",
       "                    &#x27;mousemove.hc touchdrag.hc&#x27;: function (e) {\n",
       "                        \n",
       "                        newBeta = beta + (posX - e.pageX) / sensitivity;\n",
       "                        chart.options.chart.options3d.beta = newBeta;\n",
       "\n",
       "                        newAlpha = alpha + (e.pageY - posY) / sensitivity;\n",
       "                        chart.options.chart.options3d.alpha = newAlpha;\n",
       "\n",
       "                        chart.redraw(false);\n",
       "                    },\n",
       "                    &#x27;mouseup touchend&#x27;: function () {\n",
       "                        $(document).unbind(&#x27;.hc&#x27;);\n",
       "                    }\n",
       "                });\n",
       "            });\n",
       "\n",
       "\n",
       "\n",
       " \n",
       "\n",
       "\n",
       "        \n",
       "    });\n",
       "        &lt;/script&gt;\n",
       "\n",
       "    &lt;/body&gt;\n",
       "&lt;/html&gt; \"height= 400                         width =550></iframe>"
      ],
      "text/plain": [
       "<highcharts.highcharts.highcharts.Highchart at 0x7feb09fa5c10>"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from highcharts import Highchart\n",
    "H = Highchart(width=550, height=400)\n",
    "\n",
    "\"\"\"\n",
    "This plot has two special features:\n",
    "1. color setting: the javascript setting in the beginning, which can be added by colors option in our options dict\n",
    "the option_dict in color option can be string (as shown below), list, or dict.\n",
    "2. roatation capability: the javascript function can be added using add_3dRoatation method (no input), which will \n",
    "add the function into the chart\n",
    "\"\"\"\n",
    "\n",
    "options = {\n",
    "\t'chart': {\n",
    "        'renderTo': 'container',\n",
    "        'margin': 100,\n",
    "        'type': 'scatter',\n",
    "        'options3d': {\n",
    "            'enabled': True,\n",
    "            'alpha': 10,\n",
    "            'beta': 30,\n",
    "            'depth': 250,\n",
    "            'viewDistance': 5,\n",
    "\n",
    "            'frame': {\n",
    "                'bottom': { 'size': 1, 'color': 'rgba(0,0,0,0.02)' },\n",
    "                'back': { 'size': 1, 'color': 'rgba(0,0,0,0.04)' },\n",
    "                'side': { 'size': 1, 'color': 'rgba(0,0,0,0.06)' }\n",
    "            }\n",
    "        }\n",
    "    },\n",
    "    'colors': \"\"\"Highcharts.getOptions().colors = $.map(Highcharts.getOptions().colors, function (color) {\n",
    "        return {\n",
    "            radialGradient: {\n",
    "                cx: 0.4,\n",
    "                cy: 0.3,\n",
    "                r: 0.5\n",
    "            },\n",
    "            stops: [\n",
    "                [0, color],\n",
    "                [1, Highcharts.Color(color).brighten(-0.2).get('rgb')]\n",
    "            ]\n",
    "        };\n",
    "    })\"\"\", # color setting, this function is to give points 3D like feeling\n",
    "\n",
    "    'title': {\n",
    "        'text': 'Draggable box'\n",
    "    },\n",
    "    'subtitle': {\n",
    "        'text': 'Click and drag the plot area to rotate in space'\n",
    "    },\n",
    "    'plotOptions': {\n",
    "        'scatter': {\n",
    "            'width': 10,\n",
    "            'height': 10,\n",
    "            'depth': 10\n",
    "        }\n",
    "    },\n",
    "    'yAxis': {\n",
    "        'min': 0,\n",
    "        'max': 10,\n",
    "        'title': None\n",
    "    },\n",
    "    'xAxis': {\n",
    "        'min': 0,\n",
    "        'max': 10,\n",
    "        'gridLineWidth': 1\n",
    "    },\n",
    "    'zAxis': {\n",
    "        'min': 0,\n",
    "        'max': 10,\n",
    "        'showFirstLabel': False\n",
    "    },\n",
    "    'legend': {\n",
    "        'enabled': False\n",
    "    },\n",
    "}\n",
    "\n",
    "data = [[1, 6, 5], [8, 7, 9], [1, 3, 4], [4, 6, 8], [5, 7, 7], [6, 9, 6], [7, 0, 5], [2, 3, 3], [3, 9, 8], \n",
    "        [3, 6, 5], [4, 9, 4], [2, 3, 3], [6, 9, 9], [0, 7, 0], [7, 7, 9], [7, 2, 9], [0, 6, 2], [4, 6, 7], \n",
    "        [3, 7, 7], [0, 1, 7], [2, 8, 6], [2, 3, 7], [6, 4, 8], [3, 5, 9], [7, 9, 5], [3, 1, 7], [4, 4, 2], \n",
    "        [3, 6, 2], [3, 1, 6], [6, 8, 5], [6, 6, 7], [4, 1, 1], [7, 2, 7], [7, 7, 0], [8, 8, 9], [9, 4, 1], \n",
    "        [8, 3, 4], [9, 8, 9], [3, 5, 3], [0, 2, 4], [6, 0, 2], [2, 1, 3], [5, 8, 9], [2, 1, 1], [9, 7, 6],\n",
    "        [3, 0, 2], [9, 9, 0], [3, 4, 8], [2, 6, 1], [8, 9, 2], [7, 6, 5], [6, 3, 1], [9, 3, 1], [8, 9, 3],\n",
    "        [9, 1, 0], [3, 8, 7], [8, 0, 0], [4, 9, 7], [8, 6, 2], [4, 3, 0], [2, 3, 5], [9, 1, 4], [1, 1, 4], \n",
    "        [6, 0, 2], [6, 1, 6], [3, 8, 8], [8, 8, 7], [5, 5, 0], [3, 9, 6], [5, 4, 3], [6, 8, 3], [0, 1, 5], \n",
    "        [6, 7, 3], [8, 3, 2], [3, 8, 3], [2, 1, 6], [4, 6, 7], [8, 9, 9], [5, 4, 2], [6, 1, 3], [6, 9, 5], \n",
    "        [4, 8, 2], [9, 7, 4], [5, 4, 2], [9, 6, 1], [2, 7, 3], [4, 5, 4], [6, 8, 1], [3, 4, 0], [2, 2, 6], \n",
    "        [5, 1, 2], [9, 9, 7], [6, 9, 9], [8, 4, 3], [4, 1, 7], [6, 2, 5], [0, 4, 9], [3, 5, 9], [6, 9, 1], \n",
    "        [1, 9, 2]]\n",
    "    \n",
    "H.set_dict_options(options)\n",
    "H.add_data_set(data, 'scatter', 'Reading', colorByPoint= True)\n",
    "H.add_3d_rotation() # add rotation function\n",
    "\n",
    "H"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
